﻿Imports System.Data.OleDb
Public Class Detail
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            GridView2.DataSource = SqlDataSource2
            GridView2.DataBind()
        End If
    End Sub

    Protected Sub btn_comment_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_comment.Click

        Dim OleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        OleDbConn.Open()
        Dim sqlString As String = "INSERT into comments (CommentTitle,CommentBody,Picture_fkid,Rating) VALUES (@f1,@f2,@f3,@f4)"
        Dim cm As OleDb.OleDbCommand = New OleDb.OleDbCommand(sqlString, OleDbConn)
        cm.Parameters.AddWithValue("@f1", tb_Title.Text)
        cm.Parameters.AddWithValue("@f2", tb_Body.Text)
        cm.Parameters.AddWithValue("@f3", Request.Params("ID"))
        cm.Parameters.AddWithValue("@f4", DropDownList1.SelectedValue.ToString())

        cm.CommandType = CommandType.Text
        cm.ExecuteNonQuery()
        OleDbConn.Close()
        cm.Dispose()
        OleDbConn.Dispose()

        GridView2.DataSource = SqlDataSource2
        GridView2.DataBind()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim OleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        OleDbConn.Open()
        For Each li As ListItem In CheckBoxList1.Items
            If li.Selected = True Then
                Dim sqlString As String = "INSERT into [TagsPhoto sharing AppsListJunction] (Photo Sharing AppsList_fkid,Tag_fkid) VALUES (@f1,@f2)"
                Dim cm As OleDb.OleDbCommand = New OleDb.OleDbCommand(sqlString, OleDbConn)
                cm.Parameters.AddWithValue("@f1", Request.Params("ID"))
                cm.Parameters.AddWithValue("@f2", li.Value)
                cm.CommandType = CommandType.Text
                cm.ExecuteNonQuery()
            End If
        Next
        OleDbConn.Close()
        OleDbConn.Dispose()
    End Sub
End Class